﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SimpleTaskManager.Domain.Abstract;

namespace SimpleTaskManager.WebUI.Controllers
{
    /// <summary>
    /// The controller responsible for performing actions connected to project management
    /// </summary>
    public class ProjectsController : Controller
    {
        private IProjectRepository repository;

        /// <summary>
        /// Creates a new instance of the project controller.
        /// </summary>
        /// <param name="projectRepository">A repository containing the projects in the database.</param>
        public ProjectsController(IProjectRepository projectRepository)
        {
            repository = projectRepository;
        }

        /// <summary>
        /// Page with list of the projects
        /// </summary>
        /// <returns>The rendered view</returns>
        [Authorize]
        public ViewResult Index()
        {
            return View();
        }

        /// <summary>
        /// ParitalView with a list of the projects.
        /// </summary>
        /// <returns>The rendered view</returns>
        [Authorize]
        public PartialViewResult ProjectsList()
        {
            //Indicate whether a user is allowed to create a new project
            ViewBag.CanCreateProject = User.IsInRole("SuperUser") || User.IsInRole("Manager");
            return PartialView(repository.Projects);
        }
    }
}
